class UsersController < ApplicationController

	def index
		@users = User.all		
	end

	def new
		@user = User.new
	end

	 def edit
    @user = User.find(params[:id])
  end

	def create
    @user = User.new(user_params)
    if @user.save
      redirect_to @user, notice: 'User was successfully created.'
    else
      render action: "new"
    end
  end

  def show
    @user = User.find(params[:id])
  end

  def update
  	@user = User.find(params[:id])
    if @user.update_attributes(update_params[:user])
      redirect_to @user, notice: 'User was successfully updated.'
    else
      render action: "edit"
    end
  end

  def destroy
    @user = User.find(params[:id])
    @user.destroy
    redirect_to users_url
  end


	 private
    def user_params
      params.permit(:first_name, :last_name, :email_address, :password, :password_confirmation)
      #(:user => [:last_name,:first_name, :email_address, :id], )
    end

    def update_params
      params.permit(user: [:first_name, :last_name, :email_address])
      #(:user => [:last_name,:first_name, :email_address, :id], )
    end

end
